#include <dfs_fs.h>
#include <drv_ramdisk.h>

#define DBG_TAG "app.port_ramdisk"
#define DBG_ENABLE 1
#define DBG_LVL DBG_LOG
#include <rtdbg.h>

#define DMA_SIZE (1024*1024) /*1024kB*/
#define USB_NOCACHE_RAM_SECTION __attribute__((section(".sdram")))
#define USB_MEM_ALIGNX __attribute__((aligned(32)))
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t mpool_buffer[DMA_SIZE];

static int my_ramdisk_init(void)
{
    rt_uint8_t *ramdisk_pool=mpool_buffer;
    ramdisk_init("ramdisk0", ramdisk_pool, 512, DMA_SIZE/512);

    RT_ASSERT(rt_device_find("ramdisk0") != RT_NULL);
    LOG_I("ramdisk0 device found");
   
#ifdef BSP_USING_FATFS_ROOTFS   
    dfs_unmount("/ramdisk");
    dfs_mkfs("elm", "ramdisk0");
    RT_ASSERT(dfs_mount("ramdisk0", "/ramdisk", "elm", 0, RT_NULL) == 0);
    LOG_I("mount to '/ramdisk' success!");
#endif

    return 0;
}
INIT_APP_EXPORT(my_ramdisk_init);

